Skip to content

Fix ValueError in TraceParser when parameter value contains ' = '#9

Open
fdcastel wants to merge 1 commit intoFirebirdSQL:masterfrom
fdcastel:fix-parse-parameters-maxsplit
Open

Fix ValueError in TraceParser when parameter value contains ' = '#9
fdcastel wants to merge 1 commit intoFirebirdSQL:masterfrom
fdcastel:fix-parse-parameters-maxsplit

Conversation

@fdcastel
Copy link
Copy Markdown
Member

@fdcastel fdcastel commented May 8, 2026

Summary

TraceParser._parse_parameters_block (in src/firebird/lib/trace.py) calls line.split(' = ') without a maxsplit argument. When a parameter line's value itself contains the substring = — entirely legal, since a varchar column can carry arbitrary text, including key=value-shaped strings — the split yields 3+ parts and the unpacking on the same line raises:

ValueError: too many values to unpack (expected 2, got N)

Because _parse_parameters_block is called from _parse_parameters and from __parser_func_finish (the returns: block of function-finish events), the failure silently drops the enclosing trace block on every event that carries parameters or function-return values. The error propagates out of parse_event, but typical streaming consumers swallow it per-block, and one bad row eats real telemetry.

Repro

A trace block with a parameter whose value contains =, e.g. param0 = varchar(80), \"alpha = 1; beta = 2\", triggers the ValueError before the fix. Added as test_68_param_value_containing_equals in tests/test_trace.py; without the patch, the new test fails at line 1386 with ValueError: too many values to unpack (expected 2, got 4). With the patch, all 21 tests in test_trace.py pass.

Fix

One-character change: line.split(' = ', maxsplit=1). The second = (and any after) stays inside the value, where it belongs. The expected (name, value) shape of the unpacking is preserved.

-            _, param_def = line.split(' = ')
+            _, param_def = line.split(' = ', maxsplit=1)

Both call sites of _parse_parameters_block (in _parse_parameters at line ~1390 and in __parser_func_finish at line ~1755) inherit the fix.

Out of scope

Multi-line parameter values that span multiple __current_block entries (line continuation) are a separate parsing concern and are not addressed here.

Test plan

  • pytest tests/test_trace.py passes (21/21) with the fix applied.
  • Reverting the fix while keeping the new test causes test_68_param_value_containing_equals to fail with the expected ValueError at the patched line.
  • CI green on this PR.

TraceParser._parse_parameters_block called line.split(' = ') without
maxsplit. A parameter value that itself contains the substring ' = '
(legitimate -- a varchar column can carry arbitrary text including
key=value-shaped strings) splits into 3+ parts and the unpacking
'_, param_def = ...' raises:

    ValueError: too many values to unpack (expected 2, got N)

The enclosing trace block is then dropped silently, affecting every
event that carries parameters or function-return values.

Fix: pass maxsplit=1. The second ' = ' (and any after) stays inside
the value, where it belongs. Add regression test
test_68_param_value_containing_equals exercising a varchar parameter
whose value contains two ' = ' substrings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant